package lockDemo;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author macpro
 * @date 2019-07-09
 * @function
 */
public class ReentrantLockDemo2 {
    public static void main(String[] args) {
        Home home = new Home();
        home.doHomeWork();
    }


}
class Home{
    private ReentrantLock  lock =  new ReentrantLock();

    public void doHomeWork(){
        lock.lock();
        System.out.println("doHomework");
        for (int i = 0; i < 10; i++) {
            cleanRoom(i);
        }
        System.out.println("over");
        lock.unlock();
    }

    private void cleanRoom(int i) {
        System.out.println("cleanRoom prepare");
        lock.lock();
        System.out.println("cleanRoom    ......."+System.currentTimeMillis());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        lock.unlock();
    }

}